package org.micode.demo.db.domain.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.micode.common.validater.InsertGroup;
import org.micode.common.validater.UpdateGroup;
import org.micode.common.validater.EnumValidation;
import org.micode.common.exception.VerifyFailException;
import org.micode.common.utils.StringExtUtils;
import org.micode.common.domain.base.entity.BaseUpdEntity;

import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.PositiveOrZero;
import javax.validation.constraints.Size;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

/**
 * 菜单信息实体类
 *
 * @author: wutianbin
 * @version: v1.0.27
 * @CreateDate: 2021-11-10
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class SysMenuDO extends BaseUpdEntity<Long> {

    /** 菜单ID，Long */
    @NotNull(message = "菜单ID,不能为空", groups = UpdateGroup.class)
    @PositiveOrZero(message = "菜单ID,不能为负数", groups = {InsertGroup.class, UpdateGroup.class})
    private Long menuId;

    /** 父菜单ID，一级菜单为0，Long */
    @PositiveOrZero(message = "父菜单ID，一级菜单为0,不能为负数", groups = {InsertGroup.class, UpdateGroup.class})
    private Long parentId;

    /** 应用客户端，源于sys_client，String */
    @Size(max = 32,message = "应用客户端，源于sys_client,最大长度32个字", groups = {InsertGroup.class, UpdateGroup.class})
    private String clientCode;

    /** 菜单名称，String */
    @NotNull(message = "菜单名称,不能为空", groups = InsertGroup.class)
    @Size(max = 32,message = "菜单名称,最大长度32个字", groups = {InsertGroup.class, UpdateGroup.class})
    private String menuName;

    /** 菜单编码，String */
    @Size(max = 64,message = "菜单编码,最大长度64个字", groups = {InsertGroup.class, UpdateGroup.class})
    private String menuCode;

    /** 菜单URL，String */
    @Size(max = 256,message = "菜单URL,最大长度256个字", groups = {InsertGroup.class, UpdateGroup.class})
    private String menuUrl;

    /** 菜单类型, 枚举类型: MenuTypeEnum，Integer */
    private Integer menuType;

    /** 跳转类型, 枚举类型: LinkTypeEnum，Integer */
    private Integer linkType;

    /** 接口授权(多个用逗号分隔，如：user:list,user:create)，String */
    @Size(max = 512,message = "接口授权(多个用逗号分隔，如：user:list,user:create),最大长度512个字", groups = {InsertGroup.class, UpdateGroup.class})
    private String perms;

    /** icon，String */
    @Size(max = 32,message = "icon,最大长度32个字", groups = {InsertGroup.class, UpdateGroup.class})
    private String icon;

    /** 排序号，Integer */
    private Integer sortNo;

    /** 禁用标识, 枚举类型: DisableFlagEnum，Integer */
    private Integer disableFlag;

    /** 备注说明，String */
    @Size(max = 512,message = "备注说明,最大长度512个字", groups = {InsertGroup.class, UpdateGroup.class})
    private String description;

    @JsonIgnore
    @Override
    public Long getKeyValue() {
        return menuId;
    }

    @Override
    public void checkBeforeInsert() {
        if (StringExtUtils.isAnyEmpty(menuName)) {
            throw new VerifyFailException("SysMenuDO.menuName 必须非空");
        }
    }

    @Override
    public String toString() {
        return "menuId=" + menuId +
                ", parentId=" + parentId +
                ", clientCode='" + clientCode + "'" +
                ", menuName='" + menuName + "'" +
                ", menuCode='" + menuCode + "'" +
                ", menuUrl='" + menuUrl + "'" +
                ", menuType=" + menuType +
                ", linkType=" + linkType +
                ", perms='" + perms + "'" +
                ", icon='" + icon + "'" +
                ", sortNo=" + sortNo +
                ", disableFlag=" + disableFlag +
                ", description='" + description + "'" +
                ", " + super.toString();
    }

}
